import { Component, OnInit  } from '@angular/core';

import { BaseComponent, Utils, PagedQueryResult } from 'iisp-ng';

import { LedgerCheckService } from '../ledgercheck.service.js';
import { ResultSum, ResultDetailAccount, ResultDetailNode, ResultSumPagedQueryParam } from '../model.js';

declare var contextPath : string, ngjsRoot: string;

@Component({
	selector: 'result-sum-app',
	templateUrl: contextPath + "/templates/ledgercheck/resultsum.tpl.ftl.htm",
	//styleUrls: [ngjsRoot +'/@progress/kendo-theme-default/scss/all.scss'],
	providers: [LedgerCheckService]
})

export class ResultSumComponent extends BaseComponent implements OnInit{
	result: PagedQueryResult<ResultSum>;
	queryParam: ResultSumPagedQueryParam = new ResultSumPagedQueryParam(Utils.getCurrentDataDate());
	details: ResultDetailAccount[];
	nodeDetails: ResultDetailNode[];
	dtlWindowOpened: boolean = false;
	nodeDetailOpened: boolean = false;
	selectedRum: ResultSum;
	nodeDetail: ResultDetailAccount;
	constructor(private lcService: LedgerCheckService) { super(); }

	ngOnInit(): void {
		this.searchResultSum();
	}
	
	searchResultSum(): void {
		this.lcService.searchResultSum(this.queryParam).then(result => {this.result = result}).catch(this.handleError);
	}
	changeResultSumPage(event: any) {
		this.queryParam.pageNumber = event;
		this.searchResultSum();	
	}
	getDetailsBySum(sum: ResultSum): void{
		this.selectedRum = sum;
		this.lcService.getAccountDetails(sum.dataDate, sum.accountCode, sum.ccyCode).then(result => {
			this.details = result.datas;
			this.dtlWindowOpened = true;
		}).catch(this.handleError);
	}
	closeAccountDetails(sts: string): void{
		this.dtlWindowOpened = false;
	}
	getDetailsByNode(nodeDetail: ResultDetailAccount):void {
		this.nodeDetail = nodeDetail;
		this.lcService.getNodeDetails(nodeDetail.dataDate, nodeDetail.accountCode, nodeDetail.ccyCode, nodeDetail.nodeCode).then(result => {
			this.nodeDetails = result.datas;
			this.nodeDetailOpened = true;
		}).catch(this.handleError);
		
	}
	closeNodeDetails(sts: string): void{
		this.nodeDetailOpened = false;
	}
}